<?php

namespace App\Model;


use Illuminate\Support\Facades\DB;

class ImageExamine extends BaseModel
{
    protected $table = 'image_examine';
    public $timestamps = false;

    public function getRoomImgCoverList($input = [])
    {
        $limit = $input['limit'] ?: 10;
        $page = $input['page'] ?: 1;
        $where = $input['status'] ?? 0;
        if (isset($input['uuid'])) $where .= " AND room_uid = ".$input['uuid'];
        $sql = "select r.name, r.image as r_img,i.image as i_img, r.business_type,r.room_uid, r.user_id,u.uuid, u.nickname, i.*
            from zb_image_examine i left join zb_room r on i.room_id = r.room_id left join zb_user u on u.user_id = r.user_id
            WHERE status = $where
            ";
        $data = DB::connection('api')->select($sql);
        $total = count($data);
        $data = collect($data)->forPage($page, $limit)->values()->toArray();
        return ['total' => $total, 'data' => $data, 'current_page' => intval($page)];
//        return DB::connection('api')->table("$this->table as i")
//            ->join('room as r', 'r.room_id', '=', 'i.room_id')
//            ->join('user as u', 'u.user_id', '=', 'r.user_id')
//            ->where($where)
//            ->select('r.name', 'r.image as r_img', 'i.image as i_img', 'r.business_type', 'r.room_uid', 'r.user_id', 'u.uuid', 'u.nickname', 'i.*')
//            ->orderBy('updated_at', 'desc')
//            ->paginate($limit, [], 'page', $page);
    }

    public function audioStatus($input = [])
    {
        $data['id'] = $input['id'];
        $data['room_id'] = $input['room_id'];
        $data['status'] = $input['status'];
        $data['remark'] = $input['remark'];
        $msg = new AudioApi();
        $msg->sendMsgApi($input['user_id'], $data['remark']);
        return curl_request(getKkaudioApiUrl() . '/inner/room/image/examine', $data, 'urlencoded', 'GET');
    }


}